package org.dyz.banana.platform.sample.eurakaclient2.controller;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class RestTemplateController {

	@Resource(name="restTemplate")
	RestTemplate restTemplate;
	
	@Autowired
	private LoadBalancerClient loadBalancer;
	
	/****************************当RestTemplate没有添加了@LoadBalance时 Start*************************************/
	@GetMapping("/sample2/getDataNotLoadBalance")
	public String getDataNotLoadBalance(@RequestParam("name")String name) {
		return restTemplate.getForObject("http://localhost:10000/sample/getData?name="+name, String.class);
	}
	
	@GetMapping("/sample2/getDataNotLoadBalance/{name}")
	public String getDataNotLoadBalance2(@PathVariable("name")String name) {
		return restTemplate.getForObject("http://localhost:10000/sample/getData/{name}", String.class,name);
	}
	
	@PostMapping("/sample2/setDataNotLoadBalance")
	public String setDataNotLoadBalance(@RequestParam("name")String name) {
		return restTemplate.getForObject("http://localhost:10000/sample/setData?name="+name, String.class);
	}
	
	@PostMapping("/sample2/setDataNotLoadBalance/{name}")
	public String setDataNotLoadBalance2(@PathVariable("name")String name) {
		return restTemplate.getForObject("http://localhost:10000/sample/setData/{name}", String.class,name);
	}
	/****************************当RestTemplate没有添加了@LoadBalance时 End*************************************/
	
}
